package com.hjm.project.banner.info.controller;

import java.util.List;

import com.hjm.framework.config.CustomConfig;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.banner.info.domain.BannerInfo;
import com.hjm.project.banner.info.service.IBannerInfoService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 首页banner图Controller
 * 
 * @author generator
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/banner/info")
public class BannerInfoController extends BaseController
{
    private String prefix = "banner/info";

    @Autowired
    private IBannerInfoService bannerInfoService;

    @RequiresPermissions("banner:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询首页banner图列表
     */
    @RequiresPermissions("banner:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BannerInfo bannerInfo)
    {
        startPage();
        List<BannerInfo> list = bannerInfoService.selectBannerInfoList(bannerInfo);
        return getDataTable(list);
    }

    /**
     * 新增首页banner图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页banner图
     */
    @RequiresPermissions("banner:info:add")
    @Log(title = "首页banner图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MultipartFile file, BannerInfo bannerInfo) throws Exception {
        return toAjax(bannerInfoService.insertBannerInfo(file,bannerInfo));
    }

    /**
     * 修改首页banner图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BannerInfo bannerInfo = bannerInfoService.selectBannerInfoById(id);
        bannerInfo.setUrl(CustomConfig.getImgUrl()+bannerInfo.getUrl());
        mmap.put("bannerInfo", bannerInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页banner图
     */
    @RequiresPermissions("banner:info:edit")
    @Log(title = "首页banner图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MultipartFile file, BannerInfo bannerInfo) throws Exception {
        return toAjax(bannerInfoService.updateBannerInfo(file,bannerInfo));
    }

    /**
     * 删除首页banner图
     */
    @RequiresPermissions("banner:info:remove")
    @Log(title = "首页banner图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bannerInfoService.deleteBannerInfoByIds(ids));
    }
}
